var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors'); 
/*路由（routes）*/
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

//李康飞
// var errorRouter = require('./routes/error');
var EmptyOrderRouter = require('./routes/EmptyOrder');
var MyshoppingCartRouter = require('./routes/MyshoppingCart');
var MyshoppingNullRouter = require('./routes/MyshoppingNull');
var ConfirmOrderRouter = require('./routes/ConfirmOrder');
var OrderDetailsRouter = require('./routes/OrderDetails');
var PaymentSuccessRouter = require('./routes/PaymentSuccess');
var SuccessfulSubmissionRouter = require('./routes/SuccessfulSubmission');
var FindNothingRouter = require('./routes/FindNothing');
var ErrorRouter = require('./routes/Error');
// var PubilctopRouter = require('./routes/Pubilctop');
//顾剑锋
var ProfileRouter = require('./routes/Profile');
var ProRecordRouter = require('./routes/ProRecord');
var ProPwdRouter = require('./routes/ProPwd');
var ProNoAddressRouter = require('./routes/ProNoAddress');
var ProMyPointsRouter = require('./routes/ProMyPoints');
var ProInvestRouter = require('./routes/ProInvest');
var Prohuangbang1Router = require('./routes/Prohuangbang1');
var Prohuangbang2Router = require('./routes/Prohuangbang2');
var Prohuangbang3Router = require('./routes/Prohuangbang3');
var ProdpAddressRouter = require('./routes/ProdpAddress');
var ProductAssRouter = require('./routes/ProductAss');
var ProCollectRouter = require('./routes/ProCollect');
var ProChangePhoRouter = require('./routes/ProChangePho');
var ProAssessRouter = require('./routes/ProAssess');
var ProAddressRouter = require('./routes/ProAddress');
var ProAccountRouter = require('./routes/ProAccount');
var ProMyLetterRouter = require('./routes/ProMyLetter');
var ProOrderRouter = require('./routes/ProOrder');
var ProHistoryRouter = require('./routes/ProHistory');
var ProLetterDetailRouter = require('./routes/ProLetterDetail')
//安炎
var ShenqingruzhuRouter = require('./routes/Shenqingruzhu');
var DengluRouter = require('./routes/Denglu');
var ShouyeRouter = require('./routes/Shouye');
var XanshigengduofenleiRouter = require('./routes/Xanshigengduofenlei');
var XuanzechengshiRouter = require('./routes/Xuanzechengshi');
var XuanzhongerjiRouter = require('./routes/Xuanzhongerji');
var yemianLiuRouter = require('./routes/yemianLiu');
var YShenqingruzhuRouter = require('./routes/YShenqingruzhu');
var YshangpinsousuojieguoRouter = require('./routes/Yshangpinsousuojieguo');
var YshangjiasousuojieguoRouter = require('./routes/Yshangjiasousuojieguo');
var YshangjiaRouter = require('./routes/Yshangjia');
var YquanbushangjiaxianshiRouter = require('./routes/Yquanbushangjiaxianshi');
var YjinritejiaRouter = require('./routes/Yjinritejia');
var YjingxuanqinpaiRouter = require('./routes/Yjingxuanqinpai');
var YjifenshangchangRouter = require('./routes/Yjifenshangchang');
var YijianfankuiRouter = require('./routes/Yijianfankui');
var YhangyeshangjiaRouter = require('./routes/Yhangyeshangjia');
var ZhuCeRouter = require('./routes/ZhuCe');

//师孟
var smjingxuanpinpaiRouter = require('./routes/smjingxuanpinpai');
var smjoinaddRouter = require('./routes/smjoinadd');
var smjoinclubRouter = require('./routes/smjoinclub');
var smRecordRouter = require('./routes/smRecord');
var smshowcityRouter = require('./routes/smshowcity');
var smyindaoRouter = require('./routes/smyindao');
var smyinaddRouter = require('./routes/smyinadd');





var app = express();
app.use(cors()); 
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

/*路由（views）*/
app.use('/', DengluRouter);
app.use('/users', usersRouter);
//李康飞
app.use('/EmptyOrder', EmptyOrderRouter);
app.use('/MyshoppingCart', MyshoppingCartRouter);
app.use('/MyshoppingNull', MyshoppingNullRouter);
app.use('/ConfirmOrder', ConfirmOrderRouter);
app.use('/OrderDetails', OrderDetailsRouter);
app.use('/PaymentSuccess', PaymentSuccessRouter);
app.use('/FindNothing', FindNothingRouter);
app.use('/SuccessfulSubmission', SuccessfulSubmissionRouter);
app.use('/Error',ErrorRouter)
// app.use('/Pubilctop',PubilctopRouter)

//顾剑锋
app.use('/Profile',ProfileRouter);
app.use('/ProRecord',ProRecordRouter);
app.use('/ProPwd',ProPwdRouter);
app.use('/ProNoAddress',ProNoAddressRouter);
app.use('/ProMyPoints',ProMyPointsRouter);
app.use('/ProInvest',ProInvestRouter);
app.use('/Prohuangbang1',Prohuangbang1Router);
app.use('/Prohuangbang2',Prohuangbang2Router);
app.use('/Prohuangbang3',Prohuangbang3Router);
app.use('/ProductAss',ProductAssRouter);
app.use('/ProCollect',ProCollectRouter);
app.use('/ProChangePho',ProChangePhoRouter);
app.use('/ProAssess',ProAssessRouter);
app.use('/ProAddress',ProAddressRouter);
app.use('/ProdpAddress',ProdpAddressRouter);
app.use('/ProAccount',ProAccountRouter);
app.use('/ProMyLetter',ProMyLetterRouter);
app.use('/ProOrder',ProOrderRouter);
app.use('/ProLetterDetail',ProLetterDetailRouter);
app.use('/ProHistory',ProHistoryRouter);
//安炎
app.use('/Shenqingruzhu', ShenqingruzhuRouter);
app.use('/Denglu', DengluRouter);
app.use('/Shouye', ShouyeRouter);
app.use('/Xanshigengduofenlei', XanshigengduofenleiRouter);
app.use('/Xuanzechengshi', XuanzechengshiRouter);
app.use('/Xuanzhongerji', XuanzhongerjiRouter);
app.use('/yemianLiu', yemianLiuRouter);
app.use('/YShenqingruzhu', YShenqingruzhuRouter);
app.use('/Yshangpinsousuojieguo', YshangpinsousuojieguoRouter);
app.use('/Yshangjiasousuojieguo', YshangjiasousuojieguoRouter);
app.use('/Yshangjia', YshangjiaRouter);
app.use('/Yquanbushangjiaxianshi', YquanbushangjiaxianshiRouter);
app.use('/Yjinritejia', YjinritejiaRouter);
app.use('/Yjingxuanqinpai', YjingxuanqinpaiRouter);
app.use('/Yjifenshangchang', YjifenshangchangRouter);
app.use('/Yijianfankui', YijianfankuiRouter);
app.use('/Yhangyeshangjia', YhangyeshangjiaRouter);
app.use('/ZhuCe', ZhuCeRouter);


//师孟
app.use('/smjingxuanpinpai', smjingxuanpinpaiRouter);
app.use('/smjoinadd', smjoinaddRouter);
app.use('/smjoinclub', smjoinclubRouter);
app.use('/smRecord', smRecordRouter);
app.use('/smshowcity', smshowcityRouter);
app.use('/smyindao', smyindaoRouter);
app.use('/smyinadd', smyinaddRouter);


// catch 404 and forward to error handler
app.use(function(req, res, next) {
  // next(createError(404));
  res.render('404');
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
